#ifndef BVHFILE_H
#define BVHFILE_H

#include <QObject>
#include <qfile.h>
#include <qtextstream.h>

#include "BvhJoint.h"

class BvhFile : public QObject
{
	Q_OBJECT

public:
	BvhFile();
	~BvhFile();

	void ReadBVH(QString filePath);
	void WriteBVH(QString filePath);

	int getFrameCount() { return m_frameCount; }
	double getFrameTimeInSeconds() { return m_frameTime; }
	void setFrameTimeInSeconds(double time) { m_frameTime = time; }
	BvhJoint* getRootJoint() { return m_rootJoint; }
	void setRootJoint(BvhJoint* joint) { m_rootJoint = joint; }
	BvhJoint* getJointFromName(QString jointName);

	int getDataCount() { return m_data.count(); }
	double getDataValue(int row, int col);

	void setData(int index);
	 

	QVector< QList<double> > m_data;
private:
	QPointer<BvhJoint> m_rootJoint;

	void ReadHierarchy(QTextStream& buffer);
	BvhJoint* ReadJoint(QString name, QTextStream& buffer);
	void WriteHierarchy(QTextStream& buffer);
	void WriteJoint(QTextStream& buffer, BvhJoint* jointPtr);
	void ReadMotion(QTextStream& buffer);
	void WriteMotion(QTextStream& buffer);

	int m_frameCount;
	double m_frameTime;
	int m_tabCount;
};

#endif // BVHFILE_H
